﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Basic4Net.BusinessRules;
using Basic4Net.Entities;
using Basic4Net.OAWeb.Base;

namespace Basic4Net.OAWeb.Module_Base
{
	public partial class UnFixedWordLoadSet : BasePage
	{
		protected void Page_Load(object sender, EventArgs e)
		{
            if (!IsPostBack)
                Bind();
		}

        private void Bind()
        {
            List<t_UnSetWork> list = UnSetWork.UnSetWorkInstance.FindAll(SchoolMark);

            Repeater1.DataSource = list;
            Repeater1.DataBind();
        }


        /// <summary>
        /// 验证职务名称是否重复
        /// </summary>
        /// <param name="postName"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static int ValidateItemName(string workName)
        {
            t_UnSetWork item = new t_UnSetWork();
            item.WorkName = workName;
            item.SchoolMark = SchoolMark; 
            int n = UnSetWork.UnSetWorkInstance.FindCount(item);
            return n;
        }


        /// <summary>
        /// 创建一个职务
        /// </summary>
        /// <param name="postName"></param>
        /// <param name="convertNum"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static int Insert(string workName, int convertNum,int acc)
        {
            string msg = "";
            t_UnSetWork item = new t_UnSetWork();
            item.WorkName = workName;
            item.ConvertNum = convertNum;
            item.SchoolMark = SchoolMark;
            item.ACC = acc;

            if (UnSetWork.UnSetWorkInstance.Add(item, ref msg))
                return 1;
            else
                return -1;
        }


        /// <summary>
        /// 删除职务
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static int DeleteByID(int rid)
        {
            string msg = "";
            t_UnSetWork item = new t_UnSetWork();
            item.RID = rid;

            if (UnSetWork.UnSetWorkInstance.Delete(item, ref msg))
                return 1;
            else
                return 0;
        }


        /// <summary>
        /// 更新职务信息
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static int UpdateInfo(int rid, string workName, float convertNum)
        {
            string msg = "";
            t_UnSetWork item = new t_UnSetWork();
            item.RID = rid;
            item.WorkName = workName;
            item.ConvertNum = Math.Round(convertNum,1);


            if (UnSetWork.UnSetWorkInstance.Update(item, ref msg))
                return 1;
            else
                return 0;
        }


        protected void btnItemBind_Click(object sender, EventArgs e)
        {
            Bind();
        }


        [System.Web.Services.WebMethod]
        public static int SetAcc(int workId,int acc)
        {
            bool b = UnSetWork.UnSetWorkInstance.UpdateAcc(workId, acc, SchoolMark);
            if (b)
                return 1;
            else 
                return 0;
        }
	}
}